package org.bud.data.support;

import org.bud.data.bit.ValueInfo;

import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;

/**
 * @author shaun
 * @date 2024/7/18
 * @instruction
 */
public abstract class BaseQueryDataHandler {

    public <Z> Z doneHandle(Z data, String[] keys, Consumer<ValueInfo> consumer, boolean fmt){
        for(int i = 0;i < keys.length;i++){
            consumer.accept(format(data,i,keys[i],fmt).get());
        }
        return data;
    }

    public <Z> List<Z> doneHandle(List<Z> data,String[] keys, Consumer<ValueInfo> consumer,boolean fmt){
        data.stream().forEach(o -> this.doneHandle(o,keys,consumer,fmt));
        return data;
    }

    public abstract <Z> Supplier<? extends ValueInfo> format(Z data,Integer i,String key,boolean fmt);

    public abstract void doSupport(AskSupport support);

    public <Z> Z handle(
            String[] keys, Z data, Consumer<ValueInfo> consumer, boolean fmt){
        return this.doneHandle(data,keys,consumer,fmt);
    }

    public <Z> List<Z> handle(
            String[] keys, List<Z> data, Consumer<ValueInfo> consumer, boolean fmt){
        return this.doneHandle(data,keys,consumer,fmt);
    }

}
